# +----------------------------------------------------------------------
# | ChatWork智能聊天办公系统
# +----------------------------------------------------------------------
# | 软件声明: 本系统并非自由软件,未经授权任何形式的商业使用均属非法。
# | 版权保护: 任何企业和个人不允许对程序代码以任何形式任何目的复制/分发。
# | 授权要求: 如有商业使用需求,请务必先与版权所有者取得联系并获得正式授权。
# +----------------------------------------------------------------------
# | Author: ChatWork Team <2474369941@qq.com>
# +----------------------------------------------------------------------
from common.utils.config import ConfigUtil
from apps.admin.schemas.market import register_schema as schema


class RegisterService:
    """ 注册赠送服务类 """

    @classmethod
    async def detail(cls) -> schema.RegRewardConfVo:
        """
        注册赠送配置详情

        Returns:
            schema.RegRewardConfVo: 配置详情Vo

        Author:
            zero
        """
        config = await ConfigUtil.get("register_reward") or {}
        return schema.RegRewardConfVo(
            status=int(config.get("status", "0")),
            points=int(config.get("points", "0")),
            train=int(config.get("train", "0")),
            robot=int(config.get("robot", "0")),
            know=int(config.get("know", "0")),
            mcp=int(config.get("mcp", "0"))
        )

    @classmethod
    async def save(cls, post: schema.RegRewardEditIn):
        """
        注册赠送配置保存

        Args:
            post (schema.RegRewardEditIn): 配置参数

        Author:
            zero
        """
        await ConfigUtil.set("register_reward", "status", post.status)
        await ConfigUtil.set("register_reward", "points", post.points)
        await ConfigUtil.set("register_reward", "train", post.train)
        await ConfigUtil.set("register_reward", "robot", post.robot)
        await ConfigUtil.set("register_reward", "know", post.know)
        await ConfigUtil.set("register_reward", "mcp", post.mcp)
